﻿import QtQuick 2.15
import QtQuick.Controls 2.15
import QtQuick.Layouts 1.15
//import com.example.backend 1.0
import "." // 导入项目的根目录

ApplicationWindow {
    id: mPage
    visible: true
    width: 1200
    height: 768
    title: "CalibraTech"
    // 设置背景颜色为浅灰色
    color: "#F0F0F0"

    property bool testResult: false

    MainPage{
        id: mainPage
        visible: false
    }

    CanPage {
        id: canPage
        visible:false
    }

    UartPage{
        id:uartPage
        visible: false
    }

    I2CPage {
        id:i2cPage
        visible: false
    }

    SpiPage {
        id:spiPage
        visible: false
    }

    EthrnetPage {
        id:ethrnetPage
        visible: false
    }

    PciePage {
        id:pciePage
        visible: false
    }

    GpioPage {
        id:gpioPage
        visible: false
    }

    CameraPage {
        id:cameraPage
        visible: false
    }

    ColumnLayout {
        anchors.centerIn: parent
        spacing: 20


        Label {
            id: title
            text: "CalibraTech"
            //anchors.top: parent.top
            font.pointSize: 30
            Layout.alignment: Qt.AlignCenter // 使用Layout.alignment替代anchors
            Layout.fillWidth: true
        }

        RowLayout {
            spacing: 10
            Label {
                text: "用户名："
                Layout.alignment: Qt.AlignCenter // 使用Layout.alignment替代anchors
            }
            TextField {
                id: usernameField
                //text: "dreamXd"
                //text: "j01053612"
                text:"206"
                placeholderText: "请输入用户名"
                height: 35
            }
        }

        RowLayout {
            spacing: 10
            Label {
                text: "密  码："
                Layout.alignment: Qt.AlignCenter // 使用Layout.alignment替代anchors
            }
            TextField {
                id: passwordField
                //text: "882198"
                //text: "CF206cf2063612*"
                text:"CF206cf2063293"
                placeholderText: "请输入密码"
                echoMode: TextInput.Password
                height: 35
            }
        }

        Item {
            id: spacer1
            // 用于占据一定的垂直空间，使按钮在纵向居中
            Layout.preferredHeight: (usernameField.height + passwordField.height) / 2
        }

        Row {
            spacing: 20
            //anchors.horizontalCenter: parent.horizontalCenter
            Layout.alignment: Qt.AlignVCenter // 添加这一行，使元素在垂直方向居中
            Button {
                id: validateButton
                text: "验证"
                onClicked: {
                    testResult = backend.verifyCredentials(usernameField.text, passwordField.text)
                    if (testResult) {
                        resultLabel.text = "验证正确"
                        nextButton.enabled = true
                    } else {
                        resultLabel.text = "验证错误，请重新输入"
                        nextButton.enabled = false
                    }
                }
            }

            Button {
                id: nextButton
                text: "下一步"
                enabled: false
                onClicked: {
                    // 这里可以添加进入下一步的逻辑，例如加载新的页面或执行特定的测试操作
                    //stackView.push(Qt.resolvedUrl("MainPage.qml"))
                    mainPage.visible = true
                    mPage.visible = false

                }
            }
        }

        Item {
            id: spacer2
            // 用于占据一定的垂直空间，使布局对称
            Layout.preferredHeight: (usernameField.height + passwordField.height) / 2
        }

        Label {
            id: resultLabel
            text: ""
        }
    }
}
